package com.example.resultinterceptor.entity.dto;


import lombok.AllArgsConstructor;
import lombok.Data;



@Data
public class ResultDTO<T> {
    private int code;
    private String message;
    private T data;

    public ResultDTO() {}

    public ResultDTO(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功响应
     */
    public static <T> ResultDTO<T> success(String message) {
        return new ResultDTO<>(200, message, null);
    }

    /**
     * 成功响应带数据
     */
    public static <T> ResultDTO<T> success(String message, T data) {
        return new ResultDTO<>(200, message, data);
    }

    /**
     * 错误响应
     */
    public static <T> ResultDTO<T> error(String message) {
        return new ResultDTO<>(500, message, null);
    }

    /**
     * 错误响应带状态码
     */
    public static <T> ResultDTO<T> error(int code, String message) {
        return new ResultDTO<>(code, message, null);
    }

    /**
     * 判断是否成功
     */
    public boolean isSuccess() {
        return this.code == 200;
    }
}
